<?php

class WebApiService extends FServiceBase
{
    public function getToken($params) {
        //$apiSec = $this->getModel($params['ApiSec'],'ApiSec');
        $apiSec = new ApiSec();
        $apiSec->setAttributes($params['ApiSec'],FALSE);
        
        $token = $apiSec->getNewToken();
        
        $key = 'UserSessionId';
        $sessionId = Yii::app()->session->get($key, null);
        if ( empty($sessionId))
        {
            $this->createUserSessionId();
//            $sessionId = randomString('all',32);
//            Yii::app()->session->add($key, $sessionId);
        }
        
        $this->result->processed('token',$token);
        return $this->result;
    }
    
    public function createUserSessionId($params = array()){
        $key = 'UserSessionId';
        $sessionId = randomString('all',32);
        Yii::app()->session->add($key, $sessionId);
    }
}